home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kremoteencoding.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  3.5 KB  |  128 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18.  
  19. #ifndef KREMOTEENCODING_H
  20. #define KREMOTEENCODING_H
  21.  
  22. #include <kurl.h>
  23. #include <qstring.h>
  24. #include <qcstring.h>
  25. #include <qtextcodec.h>
  26.  
  27. class KRemoteEncodingPrivate;
  28. /**
  29.  * Allows encoding and decoding properly remote filenames into Unicode.
  30.  *
  31.  * Certain protocols do not specify an appropriate encoding for decoding
  32.  * their 8-bit data into proper Unicode forms. Therefore, ioslaves should
  33.  * use this class in order to convert those forms into QStrings before
  34.  * creating the respective KIO::UDSEntry. The same is true for decoding
  35.  * URLs to its components.
  36.  *
  37.  * Each KIO::SlaveBase has one object of this kind, even if it is not necessary.
  38.  * It can be accessed through KIO::SlaveBase::remoteEncoding.
  39.  *
  40.  * @short A class for handling remote filenames
  41.  * @author Thiago Macieira <thiago.macieira@kdemail.net>
  42.  * @since 3.3
  43.  */
  44. class KIO_EXPORT KRemoteEncoding
  45. {
  46. public:
  47.   /**
  48.    * Constructor.
  49.    *
  50.    * Constructs this object to use the given encoding name.
  51.    * If @p name is a null pointer, the standard encoding will be used.
  52.    */
  53.   explicit KRemoteEncoding(const char *name = 0L);
  54.  
  55.   /**
  56.    * Destructor
  57.    */
  58.   virtual ~KRemoteEncoding();
  59.  
  60.   /**
  61.    * Converts the given full pathname or filename to Unicode.
  62.    * This function is supposed to work for dirnames, filenames
  63.    * or a full pathname.
  64.    */
  65.   QString decode(const QCString& name) const;
  66.  
  67.   /**
  68.    * Converts the given name from Unicode.
  69.    * This function is supposed to work for dirnames, filenames
  70.    * or a full pathname.
  71.    */
  72.   QCString encode(const QString& name) const;
  73.  
  74.   /**
  75.    * Converts the given URL into its 8-bit components
  76.    */
  77.   QCString encode(const KURL& url) const;
  78.  
  79.   /**
  80.    * Converts the given URL into 8-bit form and separate the
  81.    * dirname from the filename. This is useful for slave functions
  82.    * like stat or get.
  83.    *
  84.    * The dirname is returned with the final slash always stripped
  85.    */
  86.   QCString directory(const KURL& url, bool ignore_trailing_slash = true) const;
  87.  
  88.   /**
  89.    * Converts the given URL into 8-bit form and retrieve the filename.
  90.    */
  91.   QCString fileName(const KURL& url) const;
  92.  
  93.   /**
  94.    * Returns the encoding being used.
  95.    */
  96.   inline const char *encoding() const
  97.   { return codec->name(); }
  98.  
  99.   /**
  100.    * Returns the MIB for the codec being used.
  101.    */
  102.   inline int encodingMib() const
  103.   { return codec->mibEnum(); }
  104.  
  105.   /**
  106.    * Sets the encoding being used.
  107.    * This function does not change the global configuration.
  108.    *
  109.    * Pass a null pointer in @p name to revert to the standard
  110.    * encoding.
  111.    */
  112.   void setEncoding(const char* name);
  113.  
  114. protected:
  115.   QTextCodec *codec;
  116.  
  117.   virtual void virtual_hook(int id, void* data);
  118.  
  119. private:
  120.   // copy constructor
  121.   KRemoteEncoding(const KRemoteEncoding&);
  122.  
  123.  
  124.   KRemoteEncodingPrivate *d;
  125. };
  126.  
  127. #endif
  128.